<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddColumnsToUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('users', function (Blueprint $table) {
            $table->string('api_token', 128)->after('password')
                ->unique()->nullable()->default(null)->comment('API令牌');
            $table->string('mobile', 32)->default('')->after('password')
                ->unique()->nullable()->default(null)->comment('手机号');
            $table->unsignedDecimal('balance', 10, 2)->after('password')
                ->nullable()->default(0)->comment('可用余额');

//            $table->unsignedDecimal('credit_amount', 10, 2)->default(0)->comment('授信额度');
            $table->integer("points",false,true)->default(0)->comment('积分');
            $table->string('openid', 128)->unique()->nullable()->comment('微信OPENID');
            $table->string('unionid', 128)->unique()->nullable()->comment('微信UNIONID');

//            $table->string('session_key')->unique()->nullable()->comment('微信小程序用户登录状态会话密钥');
            $table->string('image')->nullable()->comment('用户头像');
            $table->string('nickname',32)->default('')->comment('用户昵称');
            $table->timestamp('deleted_at')->nullable();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('users', function (Blueprint $table) {
            $table->dropColumn([
                'api_token', 'mobile', 'balance',
                'points', 'openid', 'unionid',
                'session_key', 'image','nickname','deleted_at'
            ]);
        });
    }
}
